package jzqb.service.impl;

import haha.life.common.BelongToSqlUtils;
import haha.life.common.CutPageBean;
import jzqb.bo.AdminDepartmentBo;
import jzqb.dao.AdminDepartmentDao;
import jzqb.po.AdminDepartmentPo;
import jzqb.service.AdminDepartmentService;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

@Service
public class AdminDepartmentServiceImpl implements AdminDepartmentService {

    @Autowired
    private AdminDepartmentDao admindepartmentdao;

    @Override
    public CutPageBean<AdminDepartmentPo> cutPage (AdminDepartmentBo adminDepartmentBo){
        CutPageBean<AdminDepartmentPo> cutPageBean = new CutPageBean<>();
        List<AdminDepartmentPo> adminDepartmentList  = admindepartmentdao.cutList(adminDepartmentBo);
        int count=(int) admindepartmentdao.cutCount(adminDepartmentBo);
        cutPageBean.initCutPage(count, adminDepartmentBo.getPageSize(),adminDepartmentList);
        return cutPageBean;
    }

    @Override
    public List<AdminDepartmentPo> findAllDept() {
        return admindepartmentdao.findAllDept();
    }

    @Override
    public String getDeptNameById(String deptId) {
        String deptSql = BelongToSqlUtils.getBelongToSql(deptId.split(";"),"部门编号");
        List<AdminDepartmentBo>  depts =  admindepartmentdao.getDeptNameById(deptSql);
        StringBuffer  deptString = new StringBuffer();
        if (depts.size()>0){
        for (AdminDepartmentPo dept : depts) {
            deptString.append(dept.getDepartmentName()).append(";");
        }
        }
        return deptString.toString();
    }

    @Override
    public boolean editLeader(AdminDepartmentPo adminDepartmentPo){
        return admindepartmentdao.editLeader(adminDepartmentPo);
    };
    @Override
    public boolean isDepartmentcodeExist(String id){
        return admindepartmentdao.isDepartmentcodeExist(id);
    }

    @Override
    public boolean addDepartment(AdminDepartmentPo departmentPo, String type){
        return admindepartmentdao.addDepartment(departmentPo,type);
    }

    @Override
    public boolean deleteDepartment(AdminDepartmentPo departmentPo){
        return admindepartmentdao.deleteDepartment(departmentPo);
    }

    @Override
    public boolean writeExcelData(JSONArray jsonArray) throws IOException {
        return admindepartmentdao.writeExcelData(jsonArray);
    }

    @Override
    public boolean isDptEmpty(AdminDepartmentPo departmentPo) {
        return admindepartmentdao.isDptEmpty(departmentPo);
    }
}
